﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DAL;

namespace BLL
{
   public class ClsHienTrangKhaiThacNuocBus
    {
       public ClsHienTrangKhaiThacNuocInfo Info =new ClsHienTrangKhaiThacNuocInfo();
       public DataTable SelectAll()
       {
           ClsDataAccess oConnection = new ClsDataAccess();
           string strSql = @"SELECT TTCHUNG.TenGK,HienTrangKhaiThacNuoc.Nam,HienTrangKhaiThacNuoc.TrangThaiHD,HienTrangKhaiThacNuoc.MucNuocTinh,HienTrangKhaiThacNuoc.MucNuocDong,HienTrangKhaiThacNuoc.LuuLuongNuoc,HienTrangKhaiThacNuoc.TongLuuLuongKhaiThac,HienTrangKhaiThacNuoc.DoiTuongCapNuoc FROM HienTrangKhaiThacNuoc,TTCHUNG WHERE TTCHUNG.MaGK=HienTrangKhaiThacNuoc.IDGK AND TTCHUNG.Tinh LIKE '%" + Info.MaTinh + "%'";
           if (oConnection.ExecuteSelect(strSql))
           {
               oConnection.ODataTable.Columns.Add("STT");
               int i = 0;
               foreach (DataRow oDRow in oConnection.ODataTable.Rows)
               {
                   oDRow["STT"] = (i + 1);
                   i++;
               }
               return oConnection.ODataTable;
           }
           else return null;
       }
       public DataTable SelectOne()
       {
           ClsDataAccess oConnection = new ClsDataAccess();
           string strSql = @"SELECT TTCHUNG.TenGK,HienTrangKhaiThacNuoc.Nam,HienTrangKhaiThacNuoc.TrangThaiHD,HienTrangKhaiThacNuoc.MucNuocTinh,HienTrangKhaiThacNuoc.MucNuocDong,HienTrangKhaiThacNuoc.LuuLuongNuoc,HienTrangKhaiThacNuoc.TongLuuLuongKhaiThac,HienTrangKhaiThacNuoc.DoiTuongCapNuoc
                            FROM HienTrangKhaiThacNuoc,TTCHUNG
                            WHERE TTCHUNG.MaGK=HienTrangKhaiThacNuoc.IDGK
                            AND TTCHUNG.Tinh LIKE '%" + Info.MaTinh + 
                            "%'AND TTCHUNG.MaGK LIKE '%" + Info.IDGK + "%'";
           if (oConnection.ExecuteSelect(strSql))
           {
               oConnection.ODataTable.Columns.Add("STT");
               int i = 0;
               foreach (DataRow oDRow in oConnection.ODataTable.Rows)
               {
                   oDRow["STT"] = (i + 1);
                   i++;
               }
               return oConnection.ODataTable;
           }
           else return null;
       }
       public bool Them()
       {
           string strSql = "EXECUTE InsertHienTrangKhaiThacNuoc '" + Info.IDGK + "', '" + Info.Nam + "', N'" + Info.TrangThaiHD + "', '" + Info.MucNuocTinh + "', '" + Info.MucNuocDong + "', '" + Info.LuuLuongNuoc + "', '" + Info.TongLuLuongKhaiThac + "', N'" +Info.DoiTuongCapNuoc +"'";
           ClsDataAccess oConnection = new ClsDataAccess();
           return (oConnection.ExecuteStoredProcedure(strSql));
       }

       public bool Sua()
       {
           string strSql = "EXECUTE UpdateHienTrangKhaiThacNuoc '" + Info.IDGK + "', '" + Info.Nam + "', N'" + Info.TrangThaiHD + "', '" + Info.MucNuocTinh + "', '" + Info.MucNuocDong + "', '" + Info.LuuLuongNuoc + "', '" + Info.TongLuLuongKhaiThac + "', N'" + Info.DoiTuongCapNuoc + "'";
           ClsDataAccess oConnection = new ClsDataAccess();
           return (oConnection.ExecuteStoredProcedure(strSql));
       }

       public bool Xoa()
       {
           string strSql = "EXECUTE DeleteHienTrangKhaiThacNuoc'" + Info.IDGK+ "','"+Info.Nam+"'";
           ClsDataAccess oConnection = new ClsDataAccess();
           return (oConnection.ExecuteStoredProcedure(strSql));

       }
    }
}
